package com.whfc.ms.api.sys.service.impl;

import com.whfc.common.enums.AppType;
import com.whfc.common.weixin.bean.OAuthUserInfo;
import com.whfc.fuum.entity.WxUser;
import com.whfc.fuum.service.WxUserService;
import com.whfc.ms.api.sys.service.MsLoginService;
import com.whfc.ms.api.sys.service.WxOAuthApiService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 登录相关的接口
 *
 * @author guodong_sun
 * @Description:
 * @date 2019年7月23日
 */
@Service
public class MsLoginServiceImpl implements MsLoginService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxOAuthApiService oAuthApiService;

    @DubboReference(interfaceClass = WxUserService.class, version = "1.0.0")
    private WxUserService wxUserService;

    @Override
    public WxUser getWxUserByCode(String code) {

        OAuthUserInfo userInfo = oAuthApiService.getUserInfoByCode(AppType.CMS, code);

        return wxUserService.saveUser(AppType.CMS, userInfo);
    }
}


